import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gczn_hd/app/core/base/base_view.dart';
import 'package:gczn_hd/app/core/values/app_colors.dart';
import 'package:gczn_hd/app/core/values/app_values.dart';
import 'package:gczn_hd/app/core/values/text_styles.dart';
import 'package:gczn_hd/app/core/widget/custom_app_bar.dart';
import 'package:gczn_hd/app/core/widget/gczn_page.dart';
import 'package:gczn_hd/app/modules/ppm/sop_file/widget/sop_file_list.dart';

import 'package:get/get.dart';

import '../controllers/sop_file_controller.dart';

class SopFileView extends BaseView<SopFileController> {

  final Size boxSize = Size(360.w, 60.h);

  @override
  PreferredSizeWidget? appBar(BuildContext context) => const CustomAppBar(appBarTitleText: "SOP文件");


  @override
  Widget body(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
          padding: EdgeInsets.symmetric(horizontal: AppValues.size40.w),
          margin: EdgeInsets.only(top: AppValues.size30.h),
          child: _buildSearchBar(),
        ),
        Expanded(
          flex: 1,
          child: GcznPage(
            easyController: controller.gcznPageController.value,
            onRefresh: () async {
              await controller.onRefresh();
            },
            onLoadNextPage: () async {
              await controller.onLoadNextPage();
            },
            child: SingleChildScrollView(
              child: Container(
                width: double.infinity,
                padding: EdgeInsets.symmetric(horizontal: AppValues.size40.w, vertical: AppValues.size40.h),
                child: SopFileList()
              ),
            ),
          ),
        )
      ],
    );
  }


  Widget _buildSearchBar(){

    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        _buildSearchInput(),
        _buildSearchFileType(),
        _buildSearchFileClass()
      ],
    );
  }


  Widget _buildSearchFileClass(){

    return Row(
      mainAxisSize: MainAxisSize.min,
      children: [
        Text("文件类型", style: textStyle,),
        SizedBox(width: AppValues.margin_10.w,),
        Container(
          width: boxSize.width,
          height: boxSize.height,
          decoration: BoxDecoration(
            border: Border.all(
              color: const Color.fromRGBO(39, 65, 80, 1),
              width: 1.0,
            ),
            borderRadius: BorderRadius.circular(AppValues.margin_12.r),
            color: AppColors.processBtn,//const Color.fromRGBO(12, 29, 46, 1),
          ),
          child: Row(
            children: [
              SizedBox(width: AppValues.size12.w,),
              Expanded(child: DropdownButton(
                value: controller.select.value,
                padding: EdgeInsets.zero,
                underline: Container(height: 0,),
                iconSize: 0,
                style:  submitButtonText.copyWith(fontSize: AppValues.size24.sp),
                items: controller.lines.map<DropdownMenuItem<String>>((String value) {
                  return DropdownMenuItem<String>(
                    value: value,
                    child: Text(value),
                  );
                }).toList(),
                onChanged: (String? newValue){
                  controller.select.value = newValue!;
                },
                dropdownColor: AppColors.gcznPrimaryBlueBg,
              ),),
              SizedBox(width: 6.w,),
              Icon(Icons.arrow_forward_ios_outlined, size: AppValues.iconSize_18.sp, color: AppColors.colorWhite,),
              SizedBox(width: AppValues.size12.w,)
            ],
          ),
        )
      ],
    );
  }
  
  
  Widget _buildSearchFileType(){
    
    return Row(
      mainAxisSize: MainAxisSize.min,
      children: [
        Text("文件格式", style: textStyle,),
        SizedBox(width: AppValues.margin_10.w,),
        Container(
          width: boxSize.width,
          height: boxSize.height,
          decoration: BoxDecoration(
            border: Border.all(
              color: const Color.fromRGBO(39, 65, 80, 1),
              width: 1.0,
            ),
            borderRadius: BorderRadius.circular(AppValues.margin_12.r),
            color: AppColors.processBtn,//const Color.fromRGBO(12, 29, 46, 1),
          ),
          child: Row(
            children: [
              SizedBox(width: AppValues.size12.w,),
              Expanded(child: DropdownButton(
                value: controller.select.value,
                padding: EdgeInsets.zero,
                underline: Container(height: 0,),
                iconSize: 0,
                style:  submitButtonText.copyWith(fontSize: AppValues.size24.sp),
                items: controller.lines.map<DropdownMenuItem<String>>((String value) {
                  return DropdownMenuItem<String>(
                    value: value,
                    child: Text(value),
                  );
                }).toList(),
                onChanged: (String? newValue){
                  controller.select.value = newValue!;
                },
                dropdownColor: AppColors.gcznPrimaryBlueBg,
              ),),
              SizedBox(width: 6.w,),
              Icon(Icons.arrow_forward_ios_outlined, size: AppValues.iconSize_18.sp, color: AppColors.colorWhite,),
              SizedBox(width: AppValues.size12.w,)
            ],
          ),
        )
      ],
    );
    
  }
  

  Widget _buildSearchInput(){
    return Row(
      mainAxisSize: MainAxisSize.min,
      children: [
        Text("文件名称", style: textStyle,),
        SizedBox(width: AppValues.margin_10.w,),
        Container(
            width: boxSize.width,
            height: boxSize.height,
            decoration: BoxDecoration(
              border: Border.all(
                color: const Color.fromRGBO(39, 65, 80, 1),
                width: 1.0,
              ),
              borderRadius: BorderRadius.circular(AppValues.margin_12.r),
              color: AppColors.processBtn,//const Color.fromRGBO(12, 29, 46, 1),
            ),
            child: Row(
              children: [
                Expanded(child: TextField(
                    style: whiteTextStyle,
                    decoration:InputDecoration(
                      hintText: "文件名称",
                      hintStyle: textStyle,
                      border:  const OutlineInputBorder(
                          borderSide: BorderSide.none,
                          borderRadius: BorderRadius.zero
                      ),
                      focusedBorder:  const OutlineInputBorder(
                        borderSide: BorderSide.none,
                      ),
                    )
                )),
                SizedBox(width: 6.w,),
                Text("搜索", style: textStyle.copyWith(color: AppColors.gcznPrimaryBlueColor),),
                SizedBox(width: 6.w,)
              ],
            )
        )
      ],
    );
  }

}
